package com.net.core.core.reuslt;


public class GeneratorResult {
    private static final String DEFAULT_SUCCESS_MESSAGE = "成功";
    private static Integer SUCCESS_CODE = ResultCode.SUCCESS.getCode();

    public GeneratorResult() {
    }

    public static <T> Response<T> genSuccessMessage(T data) {
        Response<T> result = genMessage(SUCCESS_CODE, "成功", data);
        return result;
    }


    public static <T> Response<T> genSuccessMessage(String message) {
        Response<T> result = genMessage(SUCCESS_CODE, message, null);
        return result;
    }

    public static <T> Response<T> genSuccess(T data) {
        Response<T> result = genMessage(SUCCESS_CODE, "message", data);
        return result;
    }


    public static <T> Response<T> genFailMessage(String message) {
        Response<T> result = genMessage(ResultCode.FAILED.getCode(), message, null);
        return result;
    }

    public static <T> Response<T> genFailMessage(T data, String message) {
        Response<T> result = genMessage(ResultCode.FAILED.getCode(), message, data);
        return result;
    }

    public static <T> Response<T> genFailMessage(String message, ResultCode code) {
        Response<T> result = genMessage(code.getCode(), message, null);
        return result;
    }

    public static <T> Response<T> genMessage(boolean isOk) {
        return isOk ? genSuccessMessage("请求成功") : genFailMessage("操作失败");
    }

    public static <T> Response<T> genMessage(Integer code, String message, T data) {
        Response<T> result = new Response();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }


}
